Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix status code for multipart subscriptions #3610

Merged
merged 4 commits into from
Sep 2, 2024
Merged

Fix status code for multipart subscriptions #3610

merged 4 commits into from
Sep 2, 2024

Conversation

patrick91
Copy link
Member

@patrick91 patrick91 commented Sep 2, 2024

Summary by Sourcery

Improve the multipart subscription handling by ensuring a default HTTP 200 OK status code is used when not explicitly set, and update tests to verify this behavior.

Bug Fixes:

  • Ensure that the status code defaults to HTTP 200 OK if not provided in multipart responses.

Tests:

  • Add an assertion to verify that the response status code is 200 in the multipart subscription test.

Copy link
Contributor

sourcery-ai bot commented Sep 2, 2024

Reviewer's Guide by Sourcery

This pull request improves the multipart subscriptions code by addressing the status code handling in the streaming response and adding a test case to verify the status code. It also includes a TODO comment for potential future refactoring.

File-Level Changes

Change Details Files
Ensure a default status code for multipart responses
  • Add fallback to HTTP 200 OK if status_code is not set
  • Update both FastAPI and ASGI implementations
strawberry/fastapi/router.py
strawberry/asgi/__init__.py
Add test case for multipart subscription status code
  • Assert that the response status code is 200
tests/http/test_multipart_subscription.py
Add TODO comment for potential refactoring
  • Suggest renaming 'create_multipart_response' to 'streaming response'
strawberry/fastapi/router.py

Tips
  • Trigger a new Sourcery review by commenting @sourcery-ai review on the pull request.
  • Continue your discussion with Sourcery by replying directly to review comments.
  • You can change your review settings at any time by accessing your dashboard:
    • Enable or disable the Sourcery-generated pull request summary or reviewer's guide;
    • Change the review language;
  • You can always contact us if you have any questions or feedback.

Copy link
Contributor

@sourcery-ai sourcery-ai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hey @patrick91 - I've reviewed your changes - here's some feedback:

Overall Comments:

  • Consider addressing the TODO comment about renaming the function before merging. If a rename is planned, it might be better to do it in this PR.
  • It might be helpful to add a brief comment explaining why the default 200 status code is being set when sub_response.status_code is None.
Here's what I looked at during the review
  • 🟢 General issues: all looks good
  • 🟢 Security: all looks good
  • 🟡 Testing: 1 issue found
  • 🟢 Complexity: all looks good
  • 🟢 Documentation: all looks good

Sourcery is free for open source - if you like our reviews please consider sharing them ✨
Help me be more useful! Please click 👍 or 👎 on each comment to tell me if it was helpful.

@@ -71,3 +71,5 @@ async def test_multipart_subscription(
data = [d async for d in response.streaming_json()]

assert data == [{"payload": {"data": {"echo": "Hello world"}}}]

assert response.status_code == 200
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

suggestion (testing): Consider using HTTP status constants for better readability and maintainability

Instead of using the hard-coded value 200, it's recommended to use the status.HTTP_200_OK constant from the fastapi or starlette library. This improves code readability and ensures consistency with the rest of the codebase.

Suggested change
assert response.status_code == 200
from starlette import status
assert response.status_code == status.HTTP_200_OK

@botberry
Copy link
Member

botberry commented Sep 2, 2024

Thanks for adding the RELEASE.md file!

Here's a preview of the changelog:


This release fixes an issue with the http multipart subscription where the
status code would be returned as None, instead of 200.

We also took the opportunity to update the internals to better support
additional protocols in future.

Here's the tweet text:

🆕 Release (next) is out! Thanks to @patrick91 for the PR 👏

Get it here 👉 https://strawberry.rocks/release/(next)

Copy link

codecov bot commented Sep 2, 2024

Codecov Report

All modified and coverable lines are covered by tests ✅

Project coverage is 96.79%. Comparing base (98b8563) to head (c98c4c3).
Report is 1 commits behind head on main.

Additional details and impacted files
@@            Coverage Diff             @@
##             main    #3610      +/-   ##
==========================================
+ Coverage   96.75%   96.79%   +0.03%     
==========================================
  Files         517      517              
  Lines       33528    33530       +2     
  Branches     5575     5576       +1     
==========================================
+ Hits        32441    32455      +14     
+ Misses        848      847       -1     
+ Partials      239      228      -11     

Copy link

codspeed-hq bot commented Sep 2, 2024

CodSpeed Performance Report

Merging #3610 will not alter performance

Comparing fix/multipart (c98c4c3) with main (98b8563)

Summary

✅ 15 untouched benchmarks

@patrick91 patrick91 changed the title Improve multipart subscriptions' code Fix status code for multipart subscriptions Sep 2, 2024
@patrick91
Copy link
Member Author

patrick91 commented Sep 2, 2024

I should probably also fix GET multiparts

EDIT: that works already

@patrick91 patrick91 merged commit a51d09c into main Sep 2, 2024
107 checks passed
@patrick91 patrick91 deleted the fix/multipart branch September 2, 2024 15:54
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants